import matplotlib.pyplot as plt
import numpy as np

# 设置中文字体
plt.rcParams['font.sans-serif'] = ['SimHei']  # 用来正常显示中文标签
plt.rcParams['axes.unicode_minus'] = False  # 用来正常显示负号

# 创建图形和坐标轴
fig, ax = plt.subplots(figsize=(10, 6))

# 设置数据点
x_classes = np.array([0, 8, 16, 24, 32, 40, 48, 56, 64])
gini_values = np.array([0.75, 0.7, 0.75, 0.75, 0.75, 0.75, 0.75, 0.75, 0.75])

# 绘制Gini折线
ax.plot(x_classes, gini_values, color='tab:orange', marker='o', linewidth=2, markersize=8)

# 设置坐标轴标签和标题
ax.set_xlabel('number of classes', fontsize=12)
ax.set_ylabel('max Gini', fontsize=12)
ax.set_title('max Gini', fontsize=14, fontweight='bold')

# 设置坐标轴范围
ax.set_xlim(0, 64)
ax.set_ylim(0, 1)

# 设置刻度
ax.set_xticks([0, 8, 16, 24, 32, 40, 48, 56, 64])
ax.set_yticks([0, 0.25, 0.5, 0.75, 1])

# 添加网格
ax.grid(True, linestyle='--', alpha=0.7)

# 添加数据标签
for i, (x, y) in enumerate(zip(x_classes, gini_values)):
    ax.annotate(f'{y}', (x, y), textcoords="offset points", 
                xytext=(0,10), ha='center', fontsize=9)

# 调整布局
plt.tight_layout()

# 显示图表
plt.show()